// svg-captcha npm地址：https://www.npmjs.com/package/svg-captcha
const svgCaptcha = require("svg-captcha");

const { Controller } = require("egg");
const { getResBody, getReqParams } = require("../../utils");

module.exports = class ToolController extends Controller {
  // 获取验证码
  getCaptcha() {
    const { ctx } = this;
    const { width = 100, height = 40, background = "#ddd" } = getReqParams(ctx);
    const { text, data } = svgCaptcha.create({
      size: 4,
      ignoreChars: "0o1i",
      fontSize: 40,
      noise: 3,
      color: true,
      width,
      height,
      background,
    });
    ctx.session.captcha = text;
    ctx.type = "image/svg+xml";
    ctx.body = data;
  }
};
